#ifndef _RSCOMMU_H_H_
#define _RSCOMMU_H_H_

#include <windows.h>
#include <string>
#include <vector>
#include "global.h"
#include "RSSTREAM.h"

using namespace std;

//#define UPLOAD_THREAD_NUM 1

struct GAMEITEM
{
	UINT id;
	string name;
};

class RSCOMMU
{
public:
	UINT_PTR m_socket;
	volatile bool m_exit;

	bool SendAppPack();
	bool RecvAppPack();

public:
	RSSTREAM m_stream;
	BYTE *m_buf;
	TRANSPACK *m_pack;

	UINT m_id,m_num;

	RSCOMMU();
	~RSCOMMU();

	bool Connect(USHORT directport=0);
	void DisConnect();
	
	bool InitEvent(bool useDriver);
	bool KeyEvent(BYTE ac,BYTE vk,BYTE scan);
	bool MouseEvent(BYTE ac,short x,short y);
	bool GetBufData(UINT off,UINT len,BYTE *buf);
	bool GetScreenBm(BITMAP &bm);
	bool GetScreenBitmapBits(short x,short y,UINT &len,BYTE *result);
	bool ExeDosCmd(string path,string cmd,string &result);
	bool GetDiskBlockHash(UINT id,UINT block,UINT &val);
	bool GetFileUpdateTime(string name,FILETIME *ft);
	bool SetFileUpdateTime(string name,const FILETIME *ft);
	bool GetFileHash(string name,UINT &val);
	bool GetMainInf(string item,string &result);
	bool GetProgramVersion(int &version);

	bool GetDiskData(UINT id,LONGLONG off,UINT len,BYTE *data);
	bool GetDiskBlock(UINT id,UINT block,BYTE *data,bool &zero,bool record=false);
	bool GetFileData(string name,LONGLONG off,UINT len,BYTE *data);
	bool GetFileSize(string name,LONGLONG &size);
	bool GetGameInf(UINT id,string item,string &result);
	bool DownFile(string name);
	bool UpLoadFile(string localfile);
	bool SearchGame(string name,vector<GAMEITEM> &result);

	bool PutDiskData(UINT id,LONGLONG off,UINT len,const BYTE *data);
	bool PutFileData(string name,LONGLONG off,UINT len,const BYTE *data);
	bool CreateSrvFile(string name,LONGLONG size,bool sparse=false);
	/*bool UpLoadSparseFile(UINT id);*/
	bool UpLoadSparseFileByNum(UINT id,UINT num);
	bool UpLoadCompressFileByNum(UINT id,UINT num);
	bool DownLoadCompressFileByNum(UINT id,UINT num);
	bool ScanCompressFileByNum(UINT id,UINT num);
	bool BuildBitmapByNum(UINT id,UINT num);
};

#endif